package ru.sushka.lunch.gui.models;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import ru.sushka.lunch.dao.AbstractDao;
import ru.sushka.lunch.enitiy.Course;
import ru.sushka.lunch.enitiy.MenuItem;
import ru.sushka.lunch.factory.FactoryCreator;
import ru.sushka.lunch.gui.AbstractMenuModel;

public class MenuModel implements AbstractMenuModel {
    
    private List<Course> menuList;
    private AbstractDao<Course> courseDao;
    private AbstractDao<MenuItem> menuItemDao;

    public MenuModel(){
        courseDao = FactoryCreator.getFactory().getCourseDao();
        menuItemDao = FactoryCreator.getFactory().getMenuItemDao();
        menuList = new ArrayList<Course>();
    }
    
    @Override
    public void addMenuItem(Course course) {
        menuList.add(course);
    }

    @Override
    public void removeMenuItem(Course course) {
        menuList.remove(course);
    }

    @Override
    public List<Course> getMenuList() {
        return menuList;
    }

    @Override
    public List<Course> getCourseList() {
        return courseDao.getList(""); 
    }

    @Override
    public void saveMenuList(Calendar expiryDate) {
        for(Course course: menuList){
            MenuItem item = new MenuItem(course.getId(), expiryDate);
            menuItemDao.insert(item);
        }
    }
    
    public void loadMenuList(Calendar expiryDate) {
        for(Course course: menuList){
            MenuItem item = new MenuItem(course.getId(), expiryDate);
            menuItemDao.insert(item);
        }
    }

}
